class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        if (s.size() == 0)return 0;
        int n = s.size(),ans=0;
        int a[200]={0};
        int i = 0, j = 0;
        for (; j < n; j++)
        {
    
            a[s[j]]++;
            while (i < j && a[s[j]]>1)
            {
                a[s[i]]--;
                i++;
            }
            ans = max(ans, j - i + 1);
        }
        if (a[s[j - 1]] == 1)ans = max(ans, n - i);
        return ans;
    }
};